
import React from 'react';

import './index.less';

import Icon from 'bee-icon';
import 'bee-icon/build/Icon.css';

import Popconfirm from 'bee-popconfirm';
import 'bee-popconfirm/build/Popconfirm.css';

class TreeBtnGroup extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            show: false,
            isClick: true
        }
        this.output = {
            isClick: this.isHandleClick.bind(this)
        }
    }
    isHandleClick = (isClick) => {

    }
    componentDidMount() {

    }

    componentWillUnmount() {


    }
    show = () => {
        console.log(this.props.treeNodeBtnIsClick)
        if (!this.props.treeNodeBtnIsClick) return;
        this.setState({
            show: true
        })
    }
    close = () => {
        this.setState({
            show: false
        })
    }
    render() {
        return this.renderTreeNodeBtn()
    }
    renderBtn = (btnInfo) => {
        let btnClick = 'btnClick',
            btnNoClick = 'btnNoClick';
        let { treeNodeBtnClick, treeNodeData, treeNodeBtnIsClick } = this.props;
        return btnInfo.map(item => <Icon className={treeNodeBtnIsClick ? btnClick : btnNoClick} title={item.title} type={item.type} onClick={(e) => {
            treeNodeBtnClick(e, item.btnKey, treeNodeData)
        }} />)
    }
    renderTreeNodeBtn = () => {
        let {  treeNodeData } = this.props;
        let {pkProjectpart, pkParent, innerCode, childProjectpart } = treeNodeData;
        if (pkProjectpart === 'topVirtual') {
            return <div className={'tree-node-btn '}>
                {this.renderBtn([
                    { title: '新增子级', type: 'uf-add-c-o', btnKey: 'treeAddChild' }
                ])}
            </div>
        }
        if (pkParent === 'topVirtual') {
            if (childProjectpart && Array.isArray(childProjectpart) && childProjectpart.length > 0) {
                return <div className='tree-node-btn'>
                    {this.renderBtn([
                        { title: '编辑', type: 'uf-pencil', btnKey: 'treeEdit' },
                        { title: '新增子级', type: 'uf-add-c-o', btnKey: 'treeAddChild' }
                ])}
                </div>
            }
            return <div className='tree-node-btn'>
                 {this.renderBtn([
                        { title: '编辑', type: 'uf-pencil', btnKey: 'treeEdit' },
                        { title: '新增子级', type: 'uf-add-c-o', btnKey: 'treeAddChild' }
                ])}
                {this.renderDelBtn()}
            </div>
        }
        if (innerCode && innerCode.length / 3 >= 4) {
            return <div className='tree-node-btn'>
                 {this.renderBtn([
                        { title: '编辑', type: 'uf-pencil', btnKey: 'treeEdit' },
                ])}
                {this.renderDelBtn()}
            </div>
        }
        if (childProjectpart && Array.isArray(childProjectpart) && childProjectpart.length > 0) {
            return <div className='tree-node-btn'>
                {this.renderBtn([
                        { title: '编辑', type: 'uf-pencil', btnKey: 'treeEdit' },
                        { title: '新增子级', type: 'uf-add-c-o', btnKey: 'treeAddChild' }
                ])}
            </div>
        }
        return <div className='tree-node-btn'>
            {this.renderBtn([
                        { title: '编辑', type: 'uf-pencil', btnKey: 'treeEdit' },
                        { title: '新增子级', type: 'uf-add-c-o', btnKey: 'treeAddChild' }
                ])}
            {this.renderDelBtn()}
        </div>
    }

    renderDelBtn = () => {
        let content = '你确定要删除吗?';
        let btnClick = 'btnClick',
            btnNoClick = 'btnNoClick';
        let { treeNodeBtnClick, treeNodeData, treeNodeBtnIsClick } = this.props;
        return <Popconfirm
            className="tree-btn-popconfirm"
            show={this.state.show}
            trigger="click"
            placement="right"
            content={content}
            onClick={this.show}
            onClose={(e) => {
                treeNodeBtnClick(e, "treeDel", treeNodeData);
                this.close()
            }}
            onCancel={this.close}
            rootClose
            onRootClose={this.close}
        >
            <Icon className={treeNodeBtnIsClick ? btnClick : btnNoClick} title={'删除'} type="uf-del" />
        </Popconfirm>
    }
}


export default TreeBtnGroup;